home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Networking / GetHWEthernetAddr / GetHWEthernetAddr.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-06  |  2.0 KB  |  61 lines

  1. /*
  2.     File:      GetHWEthernetAddr.c        
  3.  
  4.     Contains:    A Simple app to get and display the Hardware Ethernet Address
  5.  
  6.     Written by: Karl Groethe
  7.  
  8.     Copyright:    Copyright © 2000 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 6/28/00        Created 
  20.                 
  21.  
  22. */
  23. #include <Carbon/Carbon.h>
  24.  
  25. int main(int argc, char* argv[])
  26. {
  27.     IBNibRef         nibRef;
  28.     WindowRef         window;
  29.     ControlRef        HWEnetField;
  30.     InetInterfaceInfo    myInetInterfaceInfo;
  31.     Rect        fieldRect;
  32.     CFMutableStringRef    HWEnetAddr;
  33.     int            i;
  34.     
  35.     /*setup interface from nib file*/
  36.     CreateNibReference(CFSTR("main"), &nibRef);
  37.     SetMenuBarFromNib(nibRef, CFSTR("MainMenu"));
  38.     CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &window);
  39.     DisposeNibReference(nibRef);
  40.     
  41.     OTInetGetInterfaceInfo(&myInetInterfaceInfo,kDefaultInetInterface);
  42.     //create a mutable string to store our Ethernet Address
  43.     HWEnetAddr=CFStringCreateMutable(NULL,0);
  44.     //loop through hex bytes and append them as characters to our string.
  45.     for(i=0;i<myInetInterfaceInfo.fHWAddrLen;i++)
  46.         CFStringAppendFormat(HWEnetAddr,NULL,CFSTR("%02x "),myInetInterfaceInfo.fHWAddr[i]);
  47.     
  48.     GetWindowPortBounds(window,&fieldRect);
  49.     InsetRect(&fieldRect,96,4);
  50.     CreateStaticTextControl(window,&fieldRect,HWEnetAddr,NULL,&HWEnetField);
  51.     
  52.     /*show the window*/
  53.     ShowWindow(window);
  54.     
  55.     RunApplicationEventLoop();
  56.     
  57.     return 0;
  58. }
  59.  
  60.  
  61.